package cn.zhaopin.starter.security.token;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;
import java.util.Collections;

/**
 * Description: 手机号验证码token
 *
 * @author zuomin (myleszelic@outlook.com)
 * @date: 2021/10/29-15:19
 */
public class PhoneAndSmsAuthenticationToken extends AbstractAuthenticationToken {

    private final String phoneNumber;

    private final String smsCode;

    public PhoneAndSmsAuthenticationToken(String phoneNumber, String smsCode) {
        super(Collections.emptyList());
        this.phoneNumber = phoneNumber;
        this.smsCode = smsCode;
        super.setAuthenticated(false);
    }

    public PhoneAndSmsAuthenticationToken(String phoneNumber, String smsCode, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.phoneNumber = phoneNumber;
        this.smsCode = smsCode;
        super.setAuthenticated(false);
    }

    @Override
    public Object getCredentials() {
        return smsCode;
    }

    @Override
    public Object getPrincipal() {
        return phoneNumber;
    }
}
